package com.cn.kabalifemerchants.ui.page.activity;


import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.login.bean.MsgBean;
import com.cn.kabalifemerchants.ui.page.bean.RecruitDetailsBean;
import com.cn.kabalifemerchants.ui.page.bean.RecruitDetailsMsgListBean;
import com.cn.kabalifemerchants.ui.page.bean.RecruitListBean;
import com.cn.kabalifemerchants.ui.page.bean.UpImgBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.PostRequest;

import java.io.File;
import java.util.List;

/**
 * Created by 晓林 on 2020/9/11.
 * function:
 */
public class RecruitListPresenter extends BasePresenter<RecruitListView> {
    /**
     * 招聘列表
     *
     * @param token
     * @param page
     * @param limit
     * @param id
     */
    public void onRecruitListData(String token, int page, int limit, int id) {
        OkGo.<RecruitListBean>get(Api.API_RECRUIT_LIST)
                .headers("token", token)
                .params("type", 1)
                .params("page", page)
                .params("limit", limit)
                .params("business_id", id)
                .execute(new CacheCallBack<RecruitListBean>() {
                    @Override
                    public void onSuccess(Response<RecruitListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("商家详情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onRecruitListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onRecruitDetailsData(String token, int id) {
        OkGo.<RecruitDetailsBean>get(Api.API_RECRUIT_DETAILS)
                .headers("token", token)
                .params("id", id)
                .execute(new CacheCallBack<RecruitDetailsBean>() {
                    @Override
                    public void onSuccess(Response<RecruitDetailsBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("详情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onRecruitDetailsSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 招聘留言
     * @param token
     * @param page
     * @param limit
     * @param id
     */
    public void onRecruitDetailsMsgData(String token,int page, int limit,  int id) {
        OkGo.<RecruitDetailsMsgListBean>get(Api.API_RECRUIT_MSG)
                .headers("token", token)
                .params("recruit_id", id)
                .params("page", page)
                .params("limit", limit)
                .execute(new CacheCallBack<RecruitDetailsMsgListBean>() {
                    @Override
                    public void onSuccess(Response<RecruitDetailsMsgListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("招聘留言：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onRecruitDetailsMsgSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
